httpd编译安装
===========================================
官网：http://httpd.apache.org/
包：httpd-2.4.20.tar.bz2   
注释：此处只考虑 2.4+ 的安装与配置，基于CentOS 6 和 CentOS 7。

一：环境准备
1.1：httpd 需要的依赖
    ~]# yum -y install gcc gcc-c++ pcre pcre-devel openssl openssl-devel apr-devel apr-util-devel

1.2：注意事项。
    CentOS 6：注意事项
        apr 与 apr-util 官网下载地址：http://apr.apache.org/download.cgi
        版本要求：
            (1) apr             version >= 1.4+
                ~]# ./configure  --prefix=/usr/local/apr
                ~]# make && make install

            (2) apr-util        version >= 1.4+
                ~]# ./configure  --prefix=/usr/local/apr-util  --with-apr=/usr/local/apr
                ~]# make && make install

1.3：常见编译参数
    Configuration:
        -h, --help             显示帮助文档并退出

    Installation directories:
      --prefix=PREFIX         指定安装路径

    Fine tuning of the installation directories:
        --sysconfdir=DIR        指定配置文件路径

    Optional Features:
      --enable-load-all-modules     开启所有的加载模块
      --enable-modules=MODULE-LIST  开启模块 | "all" |"most" | "few" | "none" | "reallyall"
      --enable-mods-shared=MODULE-LIST    共享模块 |"all" | "most" | "few" | "reallyall"
      --enable-mods-static=MODULE-LIST   静态模块 |"all" | "most" | "few" | "reallyall"
      --enable-ssl            SSL/TLS ：构建 https
      --enable-mpms-shared=MPM-LIST    共享模块 | "all"
      --enable-rewrite        url 重写
      --enable-vhost-alias    虚拟主机
      --enable-proxy-fcgi     FastCGI 模块
      --enable-so            允许运行时加载DSO模块

    Optional Packages:
        --with-apr=PATH         prefix for installed APR or the full path to apr-config
        --with-apr-util=PATH    prefix for installed APU or the full path to  apu-config
        --with-mpm=MPM        指定apache默认工作模式：MPM={event|worker|prefork|winnt}
        --with-pcre=PATH        perl语言兼容正则表达式)是一个用C语言编写的正则表达式函数库。
        --with-libxml2=PATH     Libxml2 是一个xml c语言版的解析器，还支持c++、PHP、Pascal、Ruby、Tcl等语言的绑定



二：编译安装

2.1：编译安装。
    CentOS 6：
            ~]# ./configure --prefix=/usr/local/httpd --sysconfdir=/etc/httpd --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-modules=all --enable-mpms-shared=all --with-pcre --with-libxml2 --enable-cgi  --enable-so --with-mpm=prefork
    CentOS 7：
            ~]#   ./configure --prefix=/usr/local/httpd --sysconfdir=/etc/httpd --enable-modules=all --enable-mpms-shared=all --with-pcre --with-libxml2 --enable-cgi --enable-so --with-mpm=prefork

    ~]# make && make install

    注释：
        （1）--enable-mods-shared=all --enable-mods-static=all 只能选择一个，选择了 shared 之后还可以选择部分 static。（非必选）
        （2） --enable-load-all-modules 开启所有的选项，不要使用，开启了所有的会存在一些冲突，当需要的时候手动开启即可。
        （2）--enable-cgi 为模块。--with-pcre --with-libxml2 为扩展。（非必选）
        （3）--with-mpm=prefork 指定默认工作模型。（非必选）
        （4）--with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util  为 CentOS 6 系统的依赖。（CentOS 6 必选）

    查看编译了那些模块：
            ~]# ls /usr/local/httpd/modules
    查看加载了那些模块：
            ~]# /usr/local/httpd/bin/httpd -M


2.2：加入环境变量
    ~]# echo "export PATH=/usr/local/httpd/bin:$PATH" > /etc/profile.d/httpd.sh
    ~]# source /etc/profile.d/httpd.sh

（1）测试是否正常。
        自带启动脚本：
            /usr/local/httpd/bin/apachectl （start | stop | restart | graceful | graceful-stop）
        查看端口80是否被监听：
            ss -tnl



    CentOS6：

    CentOS7：
        ~]# apachectl （start | stop | restart | graceful | graceful-stop）

（3）导出库文件：
        ~]# ln -s /usr/local/httpd/include /usr/include/httpd

（4）导出man手册
    CentOS 6：
        ~]# vim /etc/man.config
    CentOS 7：
        ~]# vi /etc/man_db.conf

    写入：
        MANPATH /usr/local/httpd/man


（5）服务脚本文件
    CentOS 6：新加启动脚本。
~]# vi /etc/rc.d/init.d/httpd
-------------------------------------start----------------------------------------------
#!/bin/bash
# chkconfig: - 85 15
# description: The Apache HTTP Server is an efficient and extensible server implementing the current HTTP standards.

# Source function library.
. /etc/rc.d/init.d/functions

if [ -f /etc/sysconfig/httpd ]; then
        . /etc/sysconfig/httpd
fi

# Start httpd in the C locale by default.
HTTPD_LANG=${HTTPD_LANG-"C"}

# This will prevent initlog from swallowing up a pass-phrase prompt if
# mod_ssl needs a pass-phrase from the user.
INITLOG_ARGS=""

# Set HTTPD=/usr/sbin/httpd.worker in /etc/sysconfig/httpd to use a server
# with the thread-based "worker" MPM; BE WARNED that some modules may not
# work correctly with a thread-based MPM; notably PHP will refuse to start.

# Path to the apachectl script, server binary, and short-form for messages.
apachectl=/usr/local/httpd/bin/apachectl
httpd=${HTTPD-/usr/local/httpd/bin/httpd}
prog=httpd
pidfile=${PIDFILE-/usr/local/httpd/logs/httpd.pid}
lockfile=${LOCKFILE-/var/lock/subsys/httpd.lock}
RETVAL=0
STOP_TIMEOUT=${STOP_TIMEOUT-10}

# The semantics of these two functions differ from the way apachectl does
# things -- attempting to start while running is a failure, and shutdown
# when not running is also a failure.  So we just do it the way init scripts
# are expected to behave here.
start() {
        echo -n $"Starting $prog: "
        LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $httpd $OPTIONS
        RETVAL=$?
        echo
        [ $RETVAL = 0 ] && touch ${lockfile}
        return $RETVAL
}

# When stopping httpd, a delay (of default 10 second) is required
# before SIGKILLing the httpd parent; this gives enough time for the
# httpd parent to SIGKILL any errant children.
stop() {
    echo -n $"Stopping $prog: "
    killproc -p ${pidfile} -d ${STOP_TIMEOUT} $httpd
    RETVAL=$?
    echo
    [ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}
}
reload() {
    echo -n $"Reloading $prog: "
    if ! LANG=$HTTPD_LANG $httpd $OPTIONS -t >&/dev/null; then
        RETVAL=6
        echo $"not reloading due to configuration syntax error"
        failure $"not reloading $httpd due to configuration syntax error"
    else
        # Force LSB behaviour from killproc
        LSB=1 killproc -p ${pidfile} $httpd -HUP
        RETVAL=$?
        if [ $RETVAL -eq 7 ]; then
            failure $"httpd shutdown"
        fi
    fi
    echo
}

# See how we were called.
case "$1" in
  start)
    start
    ;;
  stop)
    stop
    ;;
  status)
        status -p ${pidfile} $httpd
    RETVAL=$?
    ;;
  restart)
    stop
    start
    ;;
  condrestart|try-restart)
    if status -p ${pidfile} $httpd >&/dev/null; then
        stop
        start
    fi
    ;;
  force-reload|reload)
        reload
    ;;
  graceful|help|configtest|fullstatus)
    $apachectl $@
    RETVAL=$?
    ;;
  *)
    echo $"Usage: $prog {start|stop|restart|condrestart|try-restart|force-reload|reload|status|fullstatus|graceful|help|configtest}"
    RETVAL=2
esac

exit $RETVAL
---------------------------------------------------end------------------------------------------------


CentOS 7 新加启动脚本：
~]# vi 
---------------------------------------------------start------------------------------------------------
[Unit]
Description=httpd
After=network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
ExecStart=/usr/local/httpd $OPTIONS -DFOREGROUND
ExecReload=/usr/sbin/httpd $OPTIONS -k graceful
ExecStop=/bin/kill -WINCH ${MAINPID}
KillSignal=SIGCONT
PrivateTmp=true

[Install]
WantedBy=multi-user.target
---------------------------------------------------end------------------------------------------------


（6）开机启动
CentOS 6：
    ~]# chkconfig --add httpd
    ~]# chkconfig --level 345 httpd on
    ~]# chkconfig --list httpd
        httpd          0:off   1:off   2:off   3:on    4:on    5:on    6:off

CentOS 7：
    

（7）系统启动与停止
    CentOS 6：
        service httpd （start | stop | restart）
    CentOS 7：
        systemctl （start | stop | restart） httpd.service

（7）语法测试
    httpd -t
